<?php 

    /**
     * This file is part of the Intelligencer package.
     * For the full copyright and license, please view the LICENSE
     * file that was distributed with this source code.
     * 
     * @author         Roman Drapeko <roman.drapeko@gmail.com>
     * @copyright      Roman Drapeko <roman.drapeko@gmail.com>, 2009 - present
     */

    /**
     * Implementation of the Scanner Result. Contains classes, interfaces and their locations.
     * @author drapeko
     */
    class itScannerResult implements itScannerResultI {

        protected $classes = array();
        protected $interfaces = array();
        
        /**
         * (non-PHPdoc)
         * @see Intelligencer/LibUtil/Scanner/itScannerResultI#setClass($className, $path)
         */
        public function setClass($className, $path) {
            list($namespace, $class) = itUtil::getLowerClassAndNS($className);
            $this->classes[$namespace][$class] = $path;
        }
        
        /**
         * (non-PHPdoc)
         * @see Intelligencer/LibUtil/Scanner/itScannerResultI#setInterface($className, $path)
         */
        public function setInterface($className, $path) {
            list($namespace, $class) = itUtil::getLowerClassAndNS($className);
            $this->interfaces[$namespace][$class] = $path;
        }
        
        /**
         * (non-PHPdoc)
         * @see Intelligencer/LibUtil/Scanner/itScannerResultI#getClass($className)
         */
        public function getClass($className) {
            if ($this->hasClass($className)) {
                list($namespace, $class) = itUtil::getLowerClassAndNS($className);
                return $this->classes[$namespace][$class];
            }
            
            return null;
        }
        
        /**
         * (non-PHPdoc)
         * @see Intelligencer/LibUtil/Scanner/itScannerResultI#getInterface($className)
         */
        public function getInterface($className) {
            if ($this->hasInterface($className)) {
                list($namespace, $class) = itUtil::getLowerClassAndNS($className);
                return $this->interfaces[$namespace][$class];
            }
            
            return null;
        }
        
        /**
         * (non-PHPdoc)
         * @see Intelligencer/LibUtil/Scanner/itScannerResultI#hasClass($className)
         */
        public function hasClass($className) {
            list($namespace, $class) = itUtil::getLowerClassAndNS($className);
            
            if (array_key_exists($namespace, $this->classes)) {
                if (array_key_exists($class, $this->classes[$namespace])) {
                    return true;
                }
            }
            
            return false;
        }
        
        /**
         * (non-PHPdoc)
         * @see Intelligencer/LibUtil/Scanner/itScannerResultI#hasInterface($className)
         */
        public function hasInterface($className) {
            list($namespace, $class) = itUtil::getLowerClassAndNS($className);
            
            if (array_key_exists($namespace, $this->interfaces)) {
                if (array_key_exists($class, $this->interfaces[$namespace])) {
                    return true;
                }
            }
            
            return false;
        }

        /**
         * (non-PHPdoc)
         * @see Intelligencer/LibUtil/Scanner/itScannerResultI#getInterfaceArray()
         */
        public function getInterfaceArray() {
            return $this->interfaces;
        }
        
        /**
         * (non-PHPdoc)
         * @see Intelligencer/LibUtil/Scanner/itScannerResultI#getClassArray()
         */
        public function getClassArray() {
            return $this->classes;
        }

    }

?>